package com.zxkj.commonpatrol.repoisity;

import com.allen.library.base.BaseHttpUtil;
import com.allen.library.interceptor.Transformer;
import com.allen.library.observer.CommonObserver;
import com.czy.basecommon.utils.base.BaseRepository;
import com.czy.basecommon.utils.constant.ItrackConstant;
import com.czy.basecommon.utils.tools.SPUtils;
import com.zxkj.commonpatrol.model.post.PointNewDevice;
import com.zxkj.commonpatrol.model.post.PostCheckPointDetail;
import com.zxkj.commonpatrol.model.post.PostDevTypeInfo;
import com.zxkj.commonpatrol.model.response.DevTypeExtendInfo;
import com.zxkj.commonpatrol.model.response.DeviceType;
import com.zxkj.commonpatrol.model.response.PointInspectDeviceResponse;
import com.zxkj.commonpatrol.model.response.PointPatrolDetailResponse;
import com.zxkj.commonpatrol.net.ETFApiHelper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import okhttp3.ResponseBody;

public class AddDeciveRepoisity extends BaseRepository {
    public AddDeciveRepoisity() {

    }



    //查看設備詳情

    public  void  ShowDetail(  String RouteInspectNo,String PointNo,String DeviceNo,MyBaseDataCallBack mDataCallBack){
        HashMap<String,Object> map=new HashMap<String, Object>();
        map.put("LoginId", SPUtils.get(ItrackConstant.LOGINID,""));
        map.put("Token", SPUtils.get(ItrackConstant.TOKEN,""));
        map.put("Lang", 1);
        PostCheckPointDetail   bean =new PostCheckPointDetail();
        bean.setDeviceNo(DeviceNo);
        bean.setPointNo(PointNo);
        bean.setRouteInspectNo(RouteInspectNo);
        ETFApiHelper.geRadomApi().GetPointInspectDeviceInfo(map,new BaseHttpUtil<PostCheckPointDetail>().convertVo2Json(bean))
                .compose(Transformer.<PointInspectDeviceResponse>switchSchedulers())
                .subscribe(new CommonObserver<PointInspectDeviceResponse>() {

                    @Override
                    protected void onError(String errorMsg) {
                        mDataCallBack.onDataFailCallBack(404,errorMsg);
                    }

                    @Override
                    protected void onSuccess(PointInspectDeviceResponse s) {

                        //回调数据
                        mDataCallBack.onDataSuccessCallBack(s);
                    }
                });
    }


    //获取设备类型
    public void  getDeviceType(String PointCode,MyBaseDataCallBack mDataCallBack){
        HashMap<String,Object> map=new HashMap<String, Object>();
        map.put("LoginId", SPUtils.get(ItrackConstant.LOGINID,""));
        map.put("Token", SPUtils.get(ItrackConstant.TOKEN,""));
        map.put("Lang", 1);
        ETFApiHelper.geRadomApi().getDeviceType(map,PointCode)
                .compose(Transformer.<List<DeviceType>>switchSchedulers())
                .subscribe(new CommonObserver<List<DeviceType>>() {

                    @Override
                    protected void onError(String errorMsg) {
                        mDataCallBack.onDataFailCallBack(404,errorMsg);
                    }

                    @Override
                    protected void onSuccess(List<DeviceType> s) {

                        //回调数据
                        mDataCallBack.onDataSuccessCallBack(s);
                    }
                });
    }
    //获取单个设备类型的自定义信息和问题集信息
    public void GetDevTypeExtendInfo(String RouteInspectNo,String DevTypeNo,MyBaseDataCallBack mDataCallBack){
        HashMap<String,Object> map=new HashMap<String, Object>();
        map.put("LoginId", SPUtils.get(ItrackConstant.LOGINID,""));
        map.put("Token", SPUtils.get(ItrackConstant.TOKEN,""));
        map.put("Lang", 1);

        PostDevTypeInfo bean=new PostDevTypeInfo();
        bean.setDevTypeNo(DevTypeNo);
        bean.setRouteInspectNo(RouteInspectNo);
        ETFApiHelper.geRadomApi().GetDevTypeExtendInfo(map,new BaseHttpUtil<PostDevTypeInfo>().convertVo2Json(bean))
                .compose(Transformer.<DevTypeExtendInfo>switchSchedulers())
                .subscribe(new CommonObserver<DevTypeExtendInfo>() {

                    @Override
                    protected void onError(String errorMsg) {
                        mDataCallBack.onDataFailCallBack(404,errorMsg);
                    }

                    @Override
                    protected void onSuccess(DevTypeExtendInfo s) {

                        //回调数据
                        mDataCallBack.onDataSuccessCallBack(s);
                    }
                });
    }


    //保存设备
    public void Save(PointNewDevice device,MyBaseDataCallBack mDataCallBack){
        HashMap<String,Object> map=new HashMap<String, Object>();
        map.put("LoginId", SPUtils.get(ItrackConstant.LOGINID,""));
        map.put("Token", SPUtils.get(ItrackConstant.TOKEN,""));
        map.put("Lang", 1);
        ETFApiHelper.geRadomApi().AddPointDevice(map,new BaseHttpUtil<PointNewDevice>().conVoMyJson(device))
                .compose(Transformer.<ResponseBody>switchSchedulers())
                .subscribe(new CommonObserver<ResponseBody>() {

                    @Override
                    protected void onError(String errorMsg) {
                        mDataCallBack.onDataFailCallBack(404,errorMsg);
                    }

                    @Override
                    protected void onSuccess(ResponseBody s) {

                        //回调数据
                        mDataCallBack.onDataSuccessCallBack(s);
                    }
                });
    }
}
